package org.cubikalabs.todolist.repository.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.cubikalabs.todolist.domain.Todo;
import org.cubikalabs.todolist.repository.ProjectRepository;
import org.springframework.stereotype.Repository;


/**
 * @author p900009 Ole C. Langfj�ran (BEKK)
 * @created 18. jan.. 2009
 * @since 1.0
 */
@Repository
public class JpaProjectRepository implements ProjectRepository
{
	@PersistenceContext
	private EntityManager em;


	@Override
	@SuppressWarnings("unchecked")
	public List<Todo> getTodoList(String username) {
		Query query = em.createQuery("from Todo where username = :username");
		
		query.setParameter("username", username);
		
		return query.getResultList();
	}

	@Override
	public Todo save(Todo todo) {
		return em.merge(todo);
	}

	@Override
	public void delete(Todo todo) {
		em.remove(todo);
	}
}
